/**
 * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ukao.pad.consts;


import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.ukao.pad.R;
import com.ukao.pad.retrofit.SignTool;
import com.ukao.pad.utils.L;
import com.ukao.pad.utils.Utils;

import java.util.HashMap;

import static com.ukao.pad.retrofit.ApiStores.API_SERVER_URL;
import static com.ukao.pad.utils.CipherUtils.md5;

/**
 * 常量类
 */
public class Constant   {
	public static final   String PRINT_SERVE="http://file.ukaocloud.cn/Mopria_Print_Service.apk"; /*打印插件*/
	public static final String READ_CARD = "read_card";
	public static  String ARG_PARAM1 = "param1";
	/**
	 *     序列号
	 */
	public    static String CODE ="";

	/**
	 * 默认状态下的本地图片
	 */
	public static int[] mHomePressedIcons = {

			R.drawable.home_mydata_pressed,
			R.drawable.home_setting_pressed,
	};
	/**
	 * 按下状态下的本地图片
	 */
	public static int[] mHomeNormalIcons = {

			R.drawable.home_mydata_normal,
			R.drawable.home_setting_normal,
	};
	/**参数加密
	 */
	public  static HashMap<String,String> createParameter(HashMap<String,String> newparams ){
////		String  code="27525668"; /*丹丹姐账号  wfj@xxd */
//		String  code ="76597052";/*陈佳测试我*/
//		String  code=SaveParamets.getCode();/*正式打包*/
//		String code="71783807";  //勇哥
		String  code ="27840837";/*谢敏测试我*/
		String	appSecret=SaveParamets.getsaveloginSign(Utils.getContext());
		String  timestamp=System.currentTimeMillis()+"";
		newparams.put("serialNum",code);
		newparams.put("appSecret", appSecret);
		newparams.put("timestamp",timestamp );
		String sign = SignTool.sign(newparams);  //签名
		newparams.remove("appSecret");
		newparams.put("sign", sign);
		return  newparams;
	}

	/**初始化ji加密参数
	 */
	public  static HashMap<String,String> firstParameter(HashMap<String,String> newparams ){

//		String  code="27525668";/*正式*/
//		String  code="76597052"; /*陈佳测试我*/
//		String  code=SaveParamets.getCode();/*正式打包*/
//		String code="71783807";  //勇哥
		String  code="27840837"; /*谢敏测试我*/
		String  timestamp=System.currentTimeMillis()+"";
		newparams.put("serialNum", code);
		newparams.put("timestamp",timestamp );
		String token = md5(md5(code) + timestamp);
		newparams.put("token",token );
		return  newparams;
	}

	public static final int REQUEST_COUNT =12;/*加载数量*/
	public static final int BATCH_COUNT =7;/*批次号*/
	public static final int CLOTHING_COUNT =11;/*衣物*/
	public static final int START_COUNT_DESTROY =111111;/*点数对话框销毁*/
	public static final int ON_DESTORY =110000;/*对话框关闭*/

	public static  void initWeb(WebSettings settings, WebView webView ) {
		settings.setJavaScriptEnabled(true); //如果访问的页面中有Javascript，则WebView必须设置支持Javascript
		settings.setJavaScriptCanOpenWindowsAutomatically(true);
		settings.setSupportZoom(true); //支持缩放
		settings.setBuiltInZoomControls(true); //支持手势缩放
		settings.setDisplayZoomControls(false); //是否显示缩放按钮

		// >= 19(SDK4.4)启动硬件加速，否则启动软件加速
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
			settings.setLoadsImagesAutomatically(true); //支持自动加载图片
		} else {
			webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
			settings.setLoadsImagesAutomatically(false);
		}

		settings.setUseWideViewPort(true); //将图片调整到适合WebView的大小
		settings.setLoadWithOverviewMode(true); //自适应屏幕
		settings.setDomStorageEnabled(true);
		settings.setSaveFormData(true);
		settings.setSupportMultipleWindows(true);
	//	settings.setAppCacheEnabled(true);
		//settings.setCacheMode(WebSettings.LOAD_DEFAULT); //优先使用缓存
		webView.setHorizontalScrollbarOverlay(true);
		webView.setHorizontalScrollBarEnabled(false);
		webView.setOverScrollMode(View.OVER_SCROLL_NEVER); // 取消WebView中滚动或拖动到顶部、底部时的阴影
		webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // 取消滚动条白边效果
	}

	public  static   String   printUrl(String  outId){
		String  webUrl="";
		if (API_SERVER_URL.equals("http://api.ukaocloud.cn/")){
			 webUrl = "http://t.ukaocloud.cn/print/" + outId;
		}else{
			webUrl = "https://www.ukaocloud.com/print/" + outId;
		}



		L.i("webUrl="+webUrl);
        return  webUrl;

	}
	public static   Bitmap createDrawable(String letter,Bitmap  mBitmap) {
		int	width = mBitmap.getWidth();
		int	height = mBitmap.getHeight();
		Bitmap imgTemp = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(imgTemp);
		Paint paint = new Paint(); // 建立画笔
		paint.setDither(true);
		paint.setFilterBitmap(true);
		Rect src = new Rect(0, 0, width, height);
		Rect dst = new Rect(0, 0, width, height);
		canvas.drawBitmap(mBitmap, src, dst, paint);

		Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG
				| Paint.DEV_KERN_TEXT_FLAG);
		textPaint.setTextSize(20.0f);
		textPaint.setTypeface(Typeface.DEFAULT_BOLD); // 采用默认的宽度
		textPaint.setColor(Color.WHITE);

		canvas.drawText(String.valueOf(letter), width /2-5, height/2+5,
				textPaint);
		canvas.save(Canvas.ALL_SAVE_FLAG);
		canvas.restore();
		/*new BitmapDrawable(Utils.getContext().getResources(), imgTemp);*/
		return  imgTemp;

	}

}



